package com.qg.auth.handler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * @Author QG
 * @Date 2023/5/25 10:44
 * @description 认证接口
 **/
public interface WebContextHandler {

    /**
     * 获取用户信息
     * @return
     * @param <T>
     */
    <T> T getUser(Class<T> clazz) throws Exception;

    Map getUser() throws Exception;

    String getTokenString(HttpServletRequest request);

    /**
     * 设置用户信息
     */
    String setUser(Object user);



    void setUser(String token);

    /**
     * 移除当前用户信息
     * @return
     */
    void removeUser();

    default HttpSession getSession() {
        HttpSession session = WebContext.getRequest().getSession();
        if(session == null) {
            throw new RuntimeException("session is empty");
        }
        return session;
    }

    default HttpServletRequest getRequest() {
        return WebContext.getRequest();
    }

    default HttpServletResponse getResponse() {
        return WebContext.getResponse();
    }

}
